function getUser() {
    $.ajax({
        type: 'GET',
        url: '/my/userinfo',
        success: res => {
            const {
                status,
                message,
                data
            } = res;
            if (status !== 0) return layui.layer.msg(message);
            render(data);
        }
    })
};
getUser();

function render(user) {
    let name = user.nickname || user.username;
    $("#welcome").html('欢迎&nbsp; ' + name);
    if (user.user_pic !== null) {
        $(".layui-nav-img").attr('src', user.user_pic).show();
        $(".text-avatar").hide();
    } else {
        let x = name[0].toUpperCase();
        $(".text-avatar").html(x).show();
        $(".layui-nav-img").hide()
    }
};

$("#tuichu").on("click", function () {
    layer.confirm('是否退出?', {
        icon: 3,
        title: '提示'
    }, function (index) {
        //do something
        sessionStorage.removeItem("token");
        location.href = '/login.html'
        layer.close(index);
    });
})